<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}" />
    <title>Title</title>
</head>
<body>
<h1>首页 index.html ${#httpServletRequest.getContextPath()}, ${pageContext.request.contextPath}</h1>
<p>
    <a th:href="${#httpServletRequest.getContextPath()}">首页</a><br>
    <a th:href="${#httpServletRequest.getContextPath() + '/hello'}">hello</a><br>
    <a href="${pageContext.request.contextPath}/hello">hello</a><br>
    <img th:src="@{/static/img/1.jpg}" /><br>
    <img src="${#httpServletRequest.getContextPath()}/1.jpg" /><br>
</p>
<script type="text/javascript" th:src="@{/static/js/vue.js}"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/axios.min.js"></script>
<script>
    function getContextPath() {
        var pathName = document.location.pathname;
        var index = pathName.substr(1).indexOf("/");
        var result = pathName.substr(0, index + 1);
        return result;
    }

    console.log("js contextPath", getContextPath())
</script>
</body>
</html>